// pages/wo/candidatesInvited/candidatesInvited.js
const app = getApp()
import request from '../../../utils/http.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {

    personId:0,
    dianPuId:0,


    searchType:0,//0 全部 1 vip  2 vvip 3 知书大使
    selectDateStart:'',//查询开始时间
    selectDateEnd:'',//查询结束时间
    selectNameOrPhone:'',//根据姓名或者电话查询

    screenHeight:0,

    zhiTuiCount:0,//直推总人数
    indexPage:1,
    maxPage:1,
    maxPageFlae:false,//最后一页标志
    searchLoading:true,
    searchLoadingComplete:false,
    arry:[],
    isgetData:false //false没有本地数据；true 有数据

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that=this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          screenHeight:  res.windowHeight-(70/750 * res.windowWidth),
        });
      }
    });

    that.setData({  
      personId: wx.getStorageSync(app.globalData.PERSON_ID),
      dianPuId:wx.getStorageSync(app.globalData.SHOPID)==''?0:wx.getStorageSync(app.globalData.SHOPID)
    })
    that.userInfoSelectToUserCount();//获取总数
  },




  //获取直推List
  userInfoSelectToUser:function(){

  if(this.data.maxPageFlae==false){
    wx.showLoading({
      title: '加载中...',
      mask: true
    })


    var that = this
  
    let data = {
      dianPuId:that.data.dianPuId,
      index:that.data.indexPage,
    }

    request.get('person/zhiJieTuiJianList', data, res => {
      
      wx.hideLoading();
     
      that.setData({
        arry: that.data.indexPage==1?res.data.list:that.data.arry.concat(res.data.list),
        indexPage:that.data.indexPage+1,
       
      }) 

      if(that.data.indexPage>that.data.maxPage){
        that.setData({
          maxPageFlae:true,
          searchLoadingComplete:true,
          searchLoading:false
        })
      }
    
    }, err => {
      wx.showToast({
        title: '处理失败，请联系技术人员', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
      wx.hideLoading();
    })



  }else{
    wx.showToast({
      title: "已经是全部数据", // 提示的内容
      icon: "none", // 图标，默认success
      duration: 1500, // 提示的延迟时间，默认1500
      mask: false, // 是否显示透明蒙层，防止触摸穿透
    })
  }

},



//根据条件，查询数量
userInfoSelectToUserCount:function(){
  this.setData({
    indexPage:1,
    maxPage:1,
    maxPageFlae:false,//最后一页标志
    searchLoading:true,
    searchLoadingComplete:false,
    zhiTuiCount:0,
    arry:[]
   })

   wx.showLoading({
    title: '加载中...',
    mask: true
  })

  var that = this


  let data = {
    dianPuId:that.data.dianPuId
  }

  request.get('person/zhiJieTuiJianRenShuLiang', data, res => {
       console.log("personInfoFromId:" + JSON.stringify(res.data))
    wx.hideLoading();
    that.setData({
      zhiTuiCount:res.data.zhiJieXiaJiShuLiang,
      maxPage:(res.data.zhiJieXiaJiShuLiang%20)==0?(res.data.zhiJieXiaJiShuLiang/20):(res.data.zhiJieXiaJiShuLiang/20+1),
      isgetData:res.data.zhiJieXiaJiShuLiang>0?true:false
    })

    if(res.data.zhiJieXiaJiShuLiang>0){
      that.userInfoSelectToUser();//获取list
    }

  
  }, err => {
    wx.showToast({
      title: '处理失败，请联系技术人员', // 提示的内容
      icon: "none", // 图标，默认success
      duration: 1000, // 提示的延迟时间，默认1500
      mask: false, // 是否显示透明蒙层，防止触摸穿透
    })
    wx.hideLoading();
  })


},


//根据姓名电话查询
userInfoByNameOrPhone(){

   this.setData({
    indexPage:1,
    maxPage:1,
    maxPageFlae:false,//最后一页标志
    searchLoading:true,
    searchLoadingComplete:false,
    zhiTuiCount:0,
    arry:[]
   })

   if(this.data.selectNameOrPhone==""||this.data.selectNameOrPhone==null){

    this.userInfoSelectToUserCount();//获取总数
   }else{

   var that = this
  wx.request({
    url: app.globalData.base_url + 'person/userInfoByNameOrPhone',
    data: {
      personId: wx.getStorageSync(app.globalData.PERSON_ID),
      nameOrPhone:that.data.selectNameOrPhone,

    },
    success: function (res) {
   // console.log("personInfoFromId:" + JSON.stringify(res.data))
      that.setData({
        zhiTuiCount:res.data.listCount,
        arry: res.data.list,
        maxPageFlae:true,
        searchLoadingComplete:true,
        searchLoading:false
      })

    }
  })
}

},

//多条件查询
searchAction:function(){

  // console.log(this.data.searchType)
  // console.log(this.data.selectDateStart)
  // console.log(this.data.selectDateEnd)

  this.userInfoSelectToUserCount();
  this.closeCameraAnimation();
},

//清空查询条件
clearnAction:function(){
  this.setData({
    searchType:0,//0 全部 1 vip  2 vvip 3 知书大使
    selectDateStart:'',//查询开始时间
    selectDateEnd:'',//查询结束时间
    selectNameOrPhone:'',//根据姓名或者电话查询
  })

  this.userInfoSelectToUserCount();
  this.closeCameraAnimation();
},


//查询输入事件
inputAction(e){
  var value = e.detail.value; 
    this.setData({
      selectNameOrPhone: value.replace(/\s+/g,"")
      })
},



//拨打电话
 makePhoneCallAction(e){
  var phone = e.currentTarget.dataset.id;
  wx.makePhoneCall({
    phoneNumber: phone 
  })
},

//复制内容
setClipboardDataAction(e){
  var phone = e.currentTarget.dataset.id;
  wx.setClipboardData({
    data: phone,
    success (res) {
      wx.getClipboardData({
        success (res) {
         // console.log(res.data) // data
        }
      })
    }
  })

},


    //选择开始时间
    bindStartDateChange(e) {
      this.setData({
        selectDateStart: e.detail.value,
        decreaseVal:130
      })
    },

    //选择结束时间
    bindEndDateChange(e){  
      this.setData({
        selectDateEnd: e.detail.value,
        decreaseVal:130
      })
    },

    //选择查询类型
    bindSelectType(e){
      var index = e.currentTarget.dataset.index;
      this.setData({
        searchType: index
      })
    },



// 执行动画
startCameraAnimation: function () {

  var that = this
  var animation = wx.createAnimation({
    duration: 500,
    transformOrigin: "50% 50%",
    timingFunction: 'ease',
  })
  that.animation = animation;
 // this.startCameraAnimation(true);//显示动画

 that.animation.translateY(50 + 'vh').step()

  that.setData({
    animationSel: that.animation.export(),
    selectDialogShow: true,
  })

},


//关闭动画
closeCameraAnimation: function (e) {
  var that = this
  var animation = wx.createAnimation({
    duration: 500,
    transformOrigin: "50% 50%",
    timingFunction: 'ease',
  })
  that.animation = animation;
 that.animation.translateY(100 + 'vh').step()
  that.setData({
    animationSel: that.animation.export(),
    selectDialogShow: false,
  })
},
  //备考工具
  bindBeiBaoTap: function() {
    
    wx.navigateTo({
      url: '/packageWoDe/pages/share/share',
    })
   
  
  
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  // /**
  //  * 页面上拉触底事件的处理函数
  //  */
  // onReachBottom: function () {

  // },

  // /**
  //  * 用户点击右上角分享
  //  */
  // onShareAppMessage: function () {

  // }
})